﻿Imports System
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Partial Public Class ControlTutorial

    Public Sub New()
        MyBase.New()
        Me.InitializeComponent()

        __EnumerateOperatorsSupported()
        __EnumerateBuiltinFunctions()
    End Sub

    Private Sub __EnumerateOperatorsSupported()
        Dim _lastInline As Inline = __OperatorsSupported

        For Each _operatorType As Type In Enhancements.Basic.Expressions.Compiler.SupportedOperatorsTypes
            Dim _representation As String = CType(_operatorType.GetProperty("Representation").GetValue(Nothing, New Object() {}), String)
            Dim _name As String = _operatorType.FullName

            Dim _run As Run = New Run("    " + _representation.PadRight(5, " "c) + " " + _name)
            _run.FontFamily = New FontFamily("Courier New")
            __Text.Inlines.InsertAfter(_lastInline, _run)
            _lastInline = _run

            Dim _linebreak As LineBreak = New LineBreak()
            __Text.Inlines.InsertAfter(_lastInline, _linebreak)
            _lastInline = _linebreak
        Next _operatorType
    End Sub

    Private Sub __EnumerateBuiltinFunctions()
        Dim _lastInline As Inline = __BuiltinFunctions

        For Each _function As Enhancements.Basic.Expressions.Functions.Function In Application.Compiler.Functions

            Dim _functionRun As Run = New Run()
            _functionRun.Text = "    " + _function.Name
            If _function.Operator IsNot Nothing Then
                _functionRun.Text += " [operator " + CType(_function.Operator.Operator.GetProperty("Representation").GetValue(Nothing, New Object() {}), String) + " , priority " + _function.Operator.Priority.ToString() + "]"
            End If
            _functionRun.FontFamily = New FontFamily("Courier New")
            __Text.Inlines.InsertAfter(_lastInline, _functionRun)
            _lastInline = _functionRun

            Dim _linebreak As LineBreak = New LineBreak()
            __Text.Inlines.InsertAfter(_lastInline, _linebreak)
            _lastInline = _linebreak

            For Each _functionSignature As Enhancements.Basic.Expressions.Functions.FunctionSignature In _function.Signatures
                Dim _functionSignatureRun As Run = New Run()
                _functionSignatureRun.Text = "    " + "    " + _functionSignature.Result.Type.Name + " "
                _functionSignatureRun.Text += _function.Name + "("
                For Each _parameter As Enhancements.Basic.Expressions.Functions.FunctionSignatureParameter In _functionSignature.Parameters
                    _functionSignatureRun.Text += _parameter.Type.Name + " " + _parameter.Name + ", "
                Next _parameter
                If _functionSignatureRun.Text.EndsWith(", ") Then
                    _functionSignatureRun.Text = _functionSignatureRun.Text.Remove(_functionSignatureRun.Text.Length - ", ".Length, ", ".Length)
                End If
                _functionSignatureRun.Text += ")"
                _functionSignatureRun.FontFamily = New FontFamily("Courier New")
                _functionSignatureRun.FontSize = Me.FontSize - 1
                __Text.Inlines.InsertAfter(_lastInline, _functionSignatureRun)
                _lastInline = _functionSignatureRun

                Dim _linebreak2 As LineBreak = New LineBreak()
                __Text.Inlines.InsertAfter(_lastInline, _linebreak2)
                _lastInline = _linebreak2
            Next _functionSignature

        Next _function
    End Sub

End Class
